package com.houweishi.module.outbound.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.module.outbound.domain.BizOutbound;
import com.houweishi.module.outbound.service.IBizOutboundService;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.common.core.page.TableDataInfo;

/**
 * 出库申请和出库记录Controller
 * 
 * @author houweishi
 * @date 2023-02-25
 */
@RestController
@RequestMapping("/module/outbound")
public class BizOutboundController extends BaseController
{
    @Autowired
    private IBizOutboundService bizOutboundService;

    /**
     * 查询出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('module:outbound:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizOutbound bizOutbound)
    {
        startPage();
        List<BizOutbound> list = bizOutboundService.selectBizOutboundList(bizOutbound);
        return getDataTable(list);
    }

    /**
     * 导出出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('module:outbound:export')")
    @Log(title = "出库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizOutbound bizOutbound)
    {
        List<BizOutbound> list = bizOutboundService.selectBizOutboundList(bizOutbound);
        ExcelUtil<BizOutbound> util = new ExcelUtil<BizOutbound>(BizOutbound.class);
        util.exportExcel(response, list, "出库记录数据");
    }

    /**
     * 获取出库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:outbound:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizOutboundService.selectBizOutboundById(id));
    }

    /**
     * 新增出库申请
     */
    @PreAuthorize("@ss.hasPermi('module:outbound:add')")
    @Log(title = "出库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizOutbound bizOutbound)
    {
        return toAjax(bizOutboundService.insertBizOutbound2(bizOutbound));
    }

    /**
     * 修改出库申请
     */
//    @PreAuthorize("@ss.hasPermi('module:outbound:edit')")
    @Log(title = "出库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizOutbound bizOutbound)
    {
        return toAjax(bizOutboundService.updateBizOutbound3(bizOutbound));
    }

    /**
     * 同意通过出库申请后，修改状态和库存
     */
//    @PreAuthorize("@ss.hasPermi('module:outbound:edit2')")
    @Log(title = "出库记录", businessType = BusinessType.UPDATE)
    @PutMapping("/put/export2")
    public AjaxResult edit2(@RequestBody BizOutbound bizOutbound)
    {
        return toAjax(bizOutboundService.updateBizOutbound2(bizOutbound));
    }


    /**
     * 删除出库记录
     */
    @PreAuthorize("@ss.hasPermi('module:outbound:remove')")
    @Log(title = "出库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizOutboundService.deleteBizOutboundByIds(ids));
    }
}
